import {ClassEnum, LaneDetailEnum, TextEnum} from '../../enum/laneStatus'
import router from '../../utils/router'
import store from '../../utils/store'
const app = getApp()

Page({
    data: {
        ClassEnum,
        TextEnum,
        isNoData: false,
        laneList: []
    },

    // 获取车道监控列表
    async getList() {
        const factoryId = store.getItem("factoryId")
        const res = await app.clientPost(`${app.ClientApi.getLaneMonitorList}/factoryId/${factoryId}`, {}, {loading: false})
        const newlist = res.list.map(item => {
            return {
                id: item.id,
                laneName: item.laneName,
                laneStatus: item.laneStatus,
                orderNumber: item.orderNumber
            }
        })
        this.setData({
            laneList: newlist
        })
    },

    // 轮询车道监控列表
    async getLaneList() {
        clearInterval(this.data.timer)
        this.data.timer = setInterval(async () => {
            await this.getList()
        }, 10000)
    },

    async onShow() {
        console.log('onShow')
        await this.getList()
        await this.getLaneList()
    },

    // 监听页面隐藏的生命周期钩子
    onHide() {
        // 清楚计时器
        clearInterval(this.data.timer)
    },

    handleClickLane(e) {
        const id = e.currentTarget.dataset.id
        store.setItem('laneId', id)
        router.push('socket', {
            query: {
                id
            }
        })
    },

});